<!doctype html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>有限差分法计算一维常物性无内热源非稳态温度场</title>
	</head>
	<body>
		<div style="width:500px; height:auto; float:left; display:inline">
		    <canvas id="tmprChart" width="500" height="400">
		      Your browser does not support HTML 5 Canvas. 
		    </canvas>
		</div>
		<br>
		<div style="width:500px; height:auto; float:left; display:inline">
			<script type="text/javascript" src="//rf.revolvermaps.com/0/0/7.js?i=58x4kn61rqm&amp;m=0&amp;c=ff0000&amp;cr1=ffffff&amp;sx=0" async="async"></script>
			<script>
				var _hmt = _hmt || [];
				(function() {
				  var hm = document.createElement("script");
				  hm.src = "https://hm.baidu.com/hm.js?c92893cdabb11ad8ca139c33152761e2";
				  var s = document.getElementsByTagName("script")[0]; 
				  s.parentNode.insertBefore(hm, s);
				})();
			</script>
		</div>
		<script type="text/javascript" src="../../js/echarts.min.js"></script>
		<script type="text/javascript">
Array.create = function(dimension, initialValue){
    var arr = [];
    for(var i=0;i<dimension;i++){
        arr[i]=initialValue;
    }
    return arr;
};

Array.prototype.clone = function(){
    var arr=[];
    for(var i=0,len=this.length;i<len;i++) {
        arr.push(this[i]);
    }
    return arr;
}

var Solution=function(tmpr){
	this.tmpr=tmpr;

	this.SetUpGeometryAndMesh=SetUpGeometryAndMesh;
	this.SetUpBoundaryCondition=SetUpBoundaryCondition;
	this.Solve=Solve;
	this.ShowResults=ShowResults;
};

function SetUpGeometryAndMesh(dx){
	tmpr=Array.create(50+1,0);
	for(var i=0;i<50+1;i++){
		xs.push(i*spaceStep);
	}
}

function SetUpBoundaryCondition(dx){
	tmpr[0]=1;//左侧
	tmpr[50]=0;//右侧
}

function Solve(timeStep,iterations){
	var a=1;//热扩散系数
	for(var iter=1;iter<iterations+1;iter++){
		for(var i=1;i<50;i++){
			tmpr[i]=tmpr[i]+timeStep*a*(tmpr[i+1]+tmpr[i-1]-2*tmpr[i])/spaceStep/spaceStep;
		}
		if(iter==101) T50s=tmpr.clone();
		if(iter==201) T100s=tmpr.clone();
		if(iter==301) T150s=tmpr.clone();
	}
}

function ShowResults(){
	var dom = document.getElementById("tmprChart");
	var tmprChart = echarts.init(dom);
	var tmprOption = {
	    //title: {text: '温度分布'},//图标题
	    tooltip: {trigger: 'axis'},//提示信息
	    xAxis: {type: 'category',data: xs,},yAxis: {type: 'value'},//x坐标和y坐标
	    series: [{name:'time=50s',data: T50s,type: 'line'},
	    		 {name:'time=100s',data: T100s,type: 'line'},
	    		 {name:'time=150s',data: T150s,type: 'line'},],
	    legend: {data:['time=50s','time=100s','time=150s',]},//图例文字
	    toolbox: {feature: {saveAsImage: {}}},//设置保存图片按钮
	};

	tmprChart.setOption(tmprOption, true);
}

var tmpr=[],T50s,T100s,T150s,xs=[],flowTime=0,timeStep=0.5,iterations=301;
var solution=new Solution(tmpr);
var spaceStep=1;//网格dx
solution.SetUpGeometryAndMesh(spaceStep);//网格
solution.SetUpBoundaryCondition(spaceStep);//设置边界条件
solution.Solve(timeStep,iterations);//求解
solution.ShowResults();//绘制结果			

		</script>
	</body>
</html>